home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / misc / vpan100.zip / VPINBOX.H < prev    next >
C/C++ Source or Header  |  1995-01-18  |  4KB  |  157 lines

  1. //
  2. //   VIRTUAL PANELS * GRAPHIC USER UNTERFACE FOR LABORATORY WORKS
  3. //
  4. //        VPINBOX.H : CLASSES: Inbox, TSInbox
  5. //
  6. //                       |     Written by O.Rasizade
  7. //    declarations       |       Sept 1992, 1993
  8. //                       |
  9. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10.  
  11. #ifndef __cplusplus
  12. #error Must use C++ 
  13. #endif
  14.  
  15. #ifndef __VPINBOX_H
  16. #define __VPINBOX_H
  17.  
  18.  
  19.  
  20. #if !defined(__VPOUTBOX_H)
  21. #include <vpoutbox.h>
  22. #endif
  23.  
  24. #if !defined(__VPBUTT_H)
  25. #include <vpbutt.h>
  26. #endif
  27.  
  28. //+++++++++++++++++++++++++++++++++++++++++++++++++
  29. //++++++++++++ CLASS   << Inbox >>  +++++++++++++++
  30. //+++++++++++++++++++++++++++++++++++++++++++++++++
  31. //---------------------- COLORS -------------------------
  32. const outboxcolors ibxcolLum={
  33.                BLUE,        // color of title
  34.                LIGHTGREEN,    // text color
  35.                YELLOW,        // high-lighted text
  36.                BLACK            // color of paper
  37.                };
  38.  
  39.  
  40. const outboxcolors ibxcolGray={
  41.                BLUE,        // color of title
  42.                YELLOW,        // text color
  43.                WHITE,        // high-lighted text
  44.                LIGHTGRAY        // color of paper
  45.                };
  46.  
  47. //------------------------------ Class declaration  --
  48.  
  49. class Inbox: public Outbox
  50. {
  51. void  XorCursor(void);
  52. friend void interrupt handler(...); // cursor formation
  53.  
  54. public:
  55.  
  56.   //----- Constructor ------- All coord. and sizes in VGA pixels ----
  57.  Inbox(
  58.     int _x0,int _y0,// left top coord where to paint the box
  59.     objtype _type,    // may be FIXED,PERM,POPUP
  60.     char *_title,     // title
  61.     int columns,    // size of box
  62.                 //---------- Hereafter are defaults
  63.     int _frame=FRAMED,        // display may FRAMED or UNFRAMED
  64.     void (far *_paintproc)()=procNULL,// proc created by programmer
  65.                        // to repaint box, only for PERM
  66.     int  _titlefont=0,int _titlefontsize=1,    //font and size of title
  67.     plaquecolors obxcolcnfg=plaquecoldflt,  //colors of board
  68.     outboxcolors _ibxcolors=ibxcolGray,
  69.     int _titlejustify=CENTER_TEXT) :
  70.  
  71.     Outbox (_x0,_y0,_type,_title,  columns,1,// size of box
  72.         _frame,_paintproc,_titlefont,_titlefontsize,
  73.         0,1,/*font of text*/  obxcolcnfg,/*colors of board*/
  74.         _ibxcolors, _titlejustify) {}
  75. // Scanf returns: 0 if Shift-Tab has been pushed
  76. //             9 if Tab
  77. //         13 if CR
  78. //         27 if ESC
  79. //         -1 if no data has been entered
  80. int  Scanf(const char *fmt,...);
  81. };//++++++++++++++ END of class Inbox+++++++++++++++++++
  82.  
  83.  
  84.  
  85. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  86. //++++++++++++++ CLASS   << TSINBOX >>  ++++++++++++++++++++
  87. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  88. template <class T>
  89. class TSInbox: public tabstop, public Inbox
  90. {
  91. protected:
  92.  
  93.  char *scanfmt;        // format of variable for scanf
  94.  char *printfmt;    // format of variable for scanf
  95.  T    *variable;    // ptr to variable accosiated with Inbox
  96.  T (far *proc)(T);   // processing of entered value if need
  97.  
  98.  public:
  99. TSInbox(
  100.     int _x0,int _y0,// left top coord where to paint the box
  101.     char *_title,     // title
  102.     int columns,    // size of box
  103.     T *_variable, // variable and its formats
  104.     char *_scanfmt,
  105.     char *_printfmt,
  106.                 //---------- Hereafter are defaults
  107.         T (far *_proc)(T) = NULL, // variable processing procedure,
  108.     int  _titlefont=SMALL_FONT,int _titlefontsize=4,//font and size of title
  109.     plaquecolors obxcolcnfg=plaquecoldflt,  //colors of board
  110.     outboxcolors _ibxcolors=ibxcolGray) :
  111.  
  112.     Inbox( _x0, _y0, FIXED, _title, columns, UNFRAMED, procNULL,
  113.            _titlefont, _titlefontsize,
  114.            obxcolcnfg, _ibxcolors, LEFT_TEXT),
  115.  
  116.     tabstop()
  117. {
  118.   scanfmt=_scanfmt; printfmt=_printfmt;
  119.   variable=_variable; proc = _proc;
  120.  }
  121.  
  122.  void  Refresh(void)
  123.     { cls(); Printf(0,printfmt,*variable); }
  124.  virtual void  Activate(void);
  125.  virtual void  Deactivate(void)
  126.     { Refresh(); }
  127. };
  128.  
  129. //----------- BODIES OF TEMPLATES ----
  130. template <class T>
  131.  void  TSInbox<T>::Activate(void)
  132. {
  133.  int msg;
  134.  cls();
  135.  Printf(1,printfmt,*variable);
  136. int ch=getch(); cls(); ungetch(ch);
  137.  switch ( Scanf(scanfmt,variable) )
  138.      {
  139.       case  0:
  140.            msg = MSG_PREVTABSTOP;    // Shift-Tab
  141.            goto process;
  142.       case  9:                // Tab
  143.       case 13:
  144.            msg = MSG_NEXTTABSTOP;    // Enter
  145.            goto process;
  146.       case 27:
  147.            msg = MSG_EXIT;        // ESC
  148.       process: butsystem::SendMessage( msg );
  149.            if ( proc!=NULL )
  150.              *variable = proc( *variable );
  151.            break;
  152.       case -1: beep;        // Format error
  153.       }
  154. }
  155.  
  156. #endif // __VPINBOX_H
  157.